//
//  ZGWGeneListViewController.m
//  1gene
//
//  Created by 张国文 on 16/6/30.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "ZGWGeneListViewController.h"
#import "JiYinJianCeJieGuoModel.h"
#import "WenXianCanKaoListViewController.h"

#define kCurrentUserToken [[NSUserDefaults standardUserDefaults]objectForKey:@"token"]

@interface ZGWGeneListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *geneListTableView; // 基因列表
@property (nonatomic, strong) NSMutableArray *geneNameArray; // 基因名字数据源

@end

@implementation ZGWGeneListViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    // navi的修改
    [self changeNavigation];
    // 添加数据源
    [self addData];
    // 布局
    [self addMySubview];
    
}

// navi的修改
- (void)changeNavigation
{
      self.navigationItem.title = @"基因列表";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 数据源
- (void)addData
{
    
    self.geneNameArray = [NSMutableArray array];
    for (NSDictionary *tempDic in self.geneListData) {
        JiYinJianCeJieGuoModel *model = [[JiYinJianCeJieGuoModel alloc] init];
        [model setValuesForKeysWithDictionary:tempDic];
        [self.geneNameArray addObject:model];
    }
}

#pragma mark - 布局
- (void)addMySubview
{
    self.geneListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStylePlain];
    self.geneListTableView.backgroundColor = [UIColor whiteColor];
    self.geneListTableView.bounces = NO;
    self.geneListTableView.delegate = self;
    self.geneListTableView.dataSource = self;
    [self.view addSubview:_geneListTableView];
}

#pragma mark - tableview代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return  self.geneNameArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"geneCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (self.geneNameArray.count > indexPath.row) {
        JiYinJianCeJieGuoModel *model = self.geneNameArray[indexPath.row];
        cell.textLabel.text = model.name;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50 * kAdjustParamater;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WenXianCanKaoListViewController *wenXianCanKaoListVC = [[WenXianCanKaoListViewController alloc] init];
    if (self.geneNameArray.count > indexPath.row) {
        if (self.isShiLiBaoGao == YES) {
            wenXianCanKaoListVC.isShiLiBaoGao = YES;
            if (indexPath.row == 0) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Lu X, Wang L, Chen S, et al. Genome-wide association study in Han Chinese identifies four new susceptibility loci for coronary artery disease.[J]. Nature Genetics, 2012, 44(8):890-4.", nil];
            } else if (indexPath.row == 1) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Hinohara K, Nakajima T, Takahashi M, et al. Replication of the association between a chromosome 9p21 polymorphism and coronary artery disease in Japanese and Korean populations[J]. Journal of Human Genetics, 2008, 53(4):357-9.", nil];
            } else if (indexPath.row == 2) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Willer C J, Sanna S, Jackson A U, et al. Newly identified loci that influence lipid concentrations and risk of coronary artery disease.[J]. Nature Genetics, 2008, 40(2):161-9.", nil];
            } else if (indexPath.row == 3) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Schunkert H, König I R, Kathiresan S, et al. Large-scale association analysis identifies 13 new susceptibility loci for coronary artery disease[J]. Nature Genetics, 2011, 43(4):333-338.", nil];
            } else if (indexPath.row == 4) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Gu Y, Liu Z, Li L, et al. OLR1, PON1 and MTHFR gene polymorphisms, conventional risk factors and the severity of coronary atherosclerosis in a Chinese Han population.[J]. Cellular Physiology & Biochemistry, 2013, 31(1):143-152.", nil];
            } else if (indexPath.row == 5) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Lu X, Wang L, Chen S, et al. Genome-wide association study in Han Chinese identifies four new susceptibility loci for coronary artery disease.[J]. Nature Genetics, 2012, 44(8):890-4.", nil];
            } else if (indexPath.row == 6) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"an Wang, et al. Genome-wide association identifies a susceptibility locus for coronary artery disease in the Chinese Han population.Nature Genetics, doi:10.1038/ng.783", nil];
            } else if (indexPath.row == 7) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Lu X, Wang L, Chen S, et al. Genome-wide association study in Han Chinese identifies four new susceptibility loci for coronary artery disease.[J]. Nature Genetics, 2012, 44(8):890-4.", nil];
            } else if (indexPath.row == 8) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Lu X, Wang L, Chen S, et al. Genome-wide association study in Han Chinese identifies four new susceptibility loci for coronary artery disease.[J]. Nature Genetics, 2012, 44(8):890-4.", nil];
            } else if (indexPath.row == 9) {
                wenXianCanKaoListVC.wenXianArray = [NSMutableArray arrayWithObjects:@"Shen G Q, Li L, Rao S, et al. Four SNPs on chromosome 9p21 in a South Korean population implicate a genetic locus that confers high cross-race risk for development of coronary artery disease.[J]. Arteriosclerosis Thrombosis & Vascular Biology, 2008, 28(2):360-5.", nil];
            }
        } else {
            JiYinJianCeJieGuoModel *model = self.geneNameArray[indexPath.row];
            NSLog(@"基因名字：%@", model.name);
            wenXianCanKaoListVC.jiYinJianCeJieGuoModel = model;
            wenXianCanKaoListVC.isShiLiBaoGao = self.isShiLiBaoGao;
        }
        
    }
    [self.navigationController pushViewController:wenXianCanKaoListVC animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
